package com.ruoyi.web.controller.TiebaForums.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.web.controller.TiebaForums.domain.TiebaForums;
import com.ruoyi.web.controller.TiebaForums.mapper.TiebaForumsMapper;
import com.ruoyi.web.controller.TiebaForums.service.ITiebaForumsService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * 贴吧管理Service业务层处理
 *
 * @author yong
 * @date 2025-03-09
 */
@Service
public class TiebaForumsServiceImpl extends ServiceImpl<TiebaForumsMapper, TiebaForums> implements ITiebaForumsService {

    @Autowired
    private TiebaForumsMapper tiebaForumsMapper;

    /**
     * 查询贴吧管理列表
     *
     * @param tiebaForums 贴吧管理
     * @return 贴吧管理
     */
    @Override
    public List<TiebaForums> selectTiebaForumsList(TiebaForums tiebaForums) {
        List<TiebaForums> tiebaForumsList = tiebaForumsMapper.selectList(buildQueryWrapper(tiebaForums));
        return tiebaForumsList;
    }

    /**
     * 用户端
     * @return
     */
    @Override
    public List<TiebaForums> selectTiebaForumsList2() {
        List<TiebaForums> tiebaForumsList = tiebaForumsMapper.selectList(buildQueryWrapper2());
        return tiebaForumsList;
    }


    private LambdaQueryWrapper<TiebaForums> buildQueryWrapper(TiebaForums query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<TiebaForums> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getName()), TiebaForums::getName, query.getName());
        lqw.eq(StringUtils.isNotBlank(query.getDescription()), TiebaForums::getDescription, query.getDescription());
        lqw.eq(StringUtils.isNotBlank(query.getImageUrl()), TiebaForums::getImageUrl, query.getImageUrl());
        lqw.eq(query.getGuanzhuCount() != null, TiebaForums::getGuanzhuCount, query.getGuanzhuCount());
        lqw.eq(query.getForumsCount() != null, TiebaForums::getForumsCount, query.getForumsCount());
        lqw.eq(query.getUserId() != null, TiebaForums::getUserId, query.getUserId());
        lqw.eq(query.getDeptId() != null, TiebaForums::getDeptId, query.getDeptId());
        lqw.like(StringUtils.isNotBlank(query.getBazhuName()), TiebaForums::getBazhuName, query.getBazhuName());
        lqw.orderByDesc(TiebaForums::getCreateTime);
        return lqw;
    }


    private LambdaQueryWrapper<TiebaForums> buildQueryWrapper2() {
        LambdaQueryWrapper<TiebaForums> lqw = Wrappers.lambdaQuery();
        lqw.orderByDesc(TiebaForums::getCreateTime);
        return lqw;
    }


}
